package com.deyuanyun.pic.ctrl.controller;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.common.util.web.Asserts;
import com.deyuanyun.pic.ctrl.controller.vo.query.EqptCpRecRecodeVO;
import com.deyuanyun.pic.ctrl.controller.vo.query.EqptQueryVO;
import com.deyuanyun.pic.ctrl.controller.vo.*;
import com.deyuanyun.pic.ctrl.enumeration.EqptTypeEnum;
import com.deyuanyun.pic.ctrl.service.EqptRecodeRectifyService;
import com.deyuanyun.pic.ctrl.service.ExternalCrsnEqptService;
import com.deyuanyun.pic.pipe.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * 外腐蚀控制设备
 * @author lijun
 * @date 2016-09-12
 * 
 * History: [修改人][时间][修改描述]
 */
@Controller
@RequestMapping("/corrctrl/EqptRecordRectify")
public class EqptRecordRectifyController extends BaseController {

    @Resource
    private ExternalCrsnEqptService externalCrsnEqptServiceImpl;
    @Resource
    private EqptRecodeRectifyService eqptRecodeRectifyServiceImpl;

    /**
     * 跳转到整改记录阴保电源设备
     */
    @RequestMapping("/RecordList.html")
    public ModelAndView eqptCppowerInit() {

        return forword("/corrctrl/repair/rectifyRecord");
    }

    /**
     * 跳转到阴保电源设备整改记录
     */
    @RequestMapping("/RecordDetails.html")
    public ModelAndView eqptCppowerRectify(String eqptId,EqptTypeEnum eqptType, ModelMap model) {

        model.addAttribute("eqptId",eqptId);
        model.addAttribute("eqptType",eqptType);

        return forword("/corrctrl/repair/rectifyRecordDetails",model);
    }

    /**
     * 查询阴保电源设备整改记录
     */
    @RequestMapping("/queryEqptCppowerRectify.json")
    @ResponseBody
    public void queryEqptCppowerRectify( EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");
        //设备信息
        List<EqptCppowerVO> cppowerList = externalCrsnEqptServiceImpl.queryEqptCppower(eqptQueryDTO);
        EqptCppowerVO cppower = null != cppowerList && cppowerList.size()!=0?cppowerList.get(0):null;
        if(null != cppower){
            AjaxSupport.sendSuccessText("success", "yyyy-MM-dd",cppower);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }

    }

    /**
     * 查询长效参比设备整改记录
     */
    @RequestMapping("/queryEqptReferenceRectify.json")
    @ResponseBody
    public void queryEqptReferenceRectify( EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");

        List<EqptReferenceVO> referenceList = externalCrsnEqptServiceImpl.queryEqptReference(eqptQueryDTO);
        EqptReferenceVO reference = null != referenceList && referenceList.size()!=0?referenceList.get(0):null;
        if(null != reference){
            AjaxSupport.sendSuccessText("success", "yyyy-MM-dd",reference);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }
    }

    /**
     * 查询阳极地床设备整改记录
     */
    @RequestMapping("/queryEqptAnodesbedRectify.json")
    @ResponseBody
    public void queryEqptAnodesbedRectify(EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");
        //设备信息
        List<EqptAnodesbedVO> anodesbedList = externalCrsnEqptServiceImpl.queryEqptAnodesbed(eqptQueryDTO);
        EqptAnodesbedVO anodesbed = null != anodesbedList && anodesbedList.size()!=0?anodesbedList.get(0):null;
        if(null != anodesbed){
            AjaxSupport.sendSuccessText("success","yyyy-MM-dd", anodesbed);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }
    }

    /**
     * 查询绝缘装置设备整改记录
     */
    @RequestMapping("/queryEqptInsulatedJointRectify.json")
    @ResponseBody
    public void queryEqptInsulatedJointRectify(EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");
        //设备信息
        List<EqptInsulatedJointVO> insulatedJointList = externalCrsnEqptServiceImpl.queryEqptInsulatedJoint(eqptQueryDTO);
        EqptInsulatedJointVO insulatedJoint = null != insulatedJointList && insulatedJointList.size()!=0?insulatedJointList.get(0):null;
        if(null != insulatedJoint){
            AjaxSupport.sendSuccessText("success", insulatedJoint);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }
        AjaxSupport.sendSuccessText("success","yyyy-MM-dd", insulatedJoint);
    }

    /**
     * 查询防浪涌保护器设备整改记录
     */
    @RequestMapping("/queryEqptAntiSurgeRectify.json")
    @ResponseBody
    public void queryEqptAntiSurgeRectify(EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");
        //设备信息
        List<EqptAntiSurgeVO> antiSurgeList = externalCrsnEqptServiceImpl.queryEqptAntiSurge(eqptQueryDTO);
        EqptAntiSurgeVO antiSurge = null != antiSurgeList && antiSurgeList.size()!=0?antiSurgeList.get(0):null;
        if(null != antiSurge){
            AjaxSupport.sendSuccessText("success","yyyy-MM-dd", antiSurge);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }
    }

    /**
     * 查询跨界线设备整改记录中设备信息
     */
    @RequestMapping("/queryEqptCpJumperRectify.json")
    @ResponseBody
    public void queryEqptCpJumperRectify( EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");
        //设备信息
        List<EqptCpJumperVO> cpJumperList = externalCrsnEqptServiceImpl.queryEqptCpJumper(eqptQueryDTO);
        EqptCpJumperVO cpJumper = null != cpJumperList && cpJumperList.size()!=0?cpJumperList.get(0):null;
        if(null != cpJumper){
            AjaxSupport.sendSuccessText("success","yyyy-MM-dd", cpJumper);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }
    }

    /**
     * 查询阴保测试桩设备整改记录
     */
    @RequestMapping("/queryEqptCptestStationRectify.json")
    @ResponseBody
    public void queryEqptCptestStationRectify(EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");
        //设备信息
        List<EqptCptestStationVO> cptestStationList = externalCrsnEqptServiceImpl.queryEqptCptestStation(eqptQueryDTO);
        EqptCptestStationVO cptestStation = null != cptestStationList && cptestStationList.size()!=0?cptestStationList.get(0):null;
        if(null != cptestStation){
            AjaxSupport.sendSuccessText("success","yyyy-MM-dd", cptestStation);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }
    }

    /**
     * 查询牺牲阳极设备整改记录中设备信息
     */
    @RequestMapping("/queryEqptSaalAnodeRectify.json")
    @ResponseBody
    public void queryEqptSaalAnodeRectify(EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");
        //设备信息
        List<EqptSaalAnodeVO> saalAnodeList = externalCrsnEqptServiceImpl.queryEqptSaalAnode(eqptQueryDTO);
        EqptSaalAnodeVO saalAnode = null != saalAnodeList && saalAnodeList.size()!=0?saalAnodeList.get(0):null;
        if(null != saalAnode){
            AjaxSupport.sendSuccessText("success","yyyy-MM-dd", saalAnode);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }
    }

    /**
     * 查询排流装置设备整改记录中设备信息
     */
    @RequestMapping("/queryEqptCurrentDrainageRectify.json")
    @ResponseBody
    public void queryEqptCurrentDrainageRectify(EqptQueryVO eqptQueryDTO) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(eqptQueryDTO.getEqptId()), "没有获取到所属设备Id");
        //设备信息
        List<EqptCurrentDrainageVO> currentDrainageList = externalCrsnEqptServiceImpl.queryEqptCurrentDrainage(eqptQueryDTO);
        EqptCurrentDrainageVO currentDrainage = null != currentDrainageList && currentDrainageList.size()!=0?currentDrainageList.get(0):null;
        if(null != currentDrainage){
            AjaxSupport.sendSuccessText("success","yyyy-MM-dd", currentDrainage);
        }else{
            AjaxSupport.sendFailText("此设备不存在或设备被删除","");
        }
    }

    /**
     * 得到设备整改记录信息
     */
    @RequestMapping("/queryEqptRecordRectify.json")
    @ResponseBody
    public void queryEqptRecordRectify(EqptCpRecRecodeVO recRecode) {
        Asserts.assertTrue(StringUtils.isNotNullEmpty(recRecode.getEqptId()), "没有获取到所属设备Id");
        //分页
        PageJsonBean pageJson = new PageJsonBean();
        //设备整改信息
        List<CpRecRecodeVO> list = eqptRecodeRectifyServiceImpl.queryCpRecRecodeByEqptId(recRecode);

        pageJson.setList(list);

        AjaxSupport.sendSuccessText("success","yyyy-MM-dd", pageJson);
    }

}
